<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/styles/layui.css"  media="all">
    <link rel="stylesheet" href="/styles/common.css"/>
    <script type="text/javascript" src="/styles/js/jquery-1.7.2.js"></script>
</head>
<body class="layui-layout-body" style="width: 100%">
<#include "managerbossmenu.ftl">
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
        <div class="content-nav">
            娱乐功能 > 抽奖内容
        </div>
        <table class="listtable">
            <caption>所有奖品:</caption>
            <tr class="listheader">
                <th>奖品id</th>
                <th>奖品内容</th>
                <th>操作</th>
            </tr>
            <#if awards??>
                <#list awards as ads>
                    <tr>
                        <td>${ads.awardid}</td>
                        <td id="awardname${ads.awardid}">${ads.awardname}</td>
                        <td>
                            <a class="clickbutton" href="#" id="edit${ads.awardid}" onclick="editDep(${ads.awardid})">编辑</a>
                            <a class="clickbutton" style="display: none" href="#" id="cancel${ads.awardid}" onclick="cancelDep(${ads.awardid})">取消</a>
                        </td>
                    </tr>
                </#list>
            </#if>

        </table>
        <#if error??> <span style="color: red">${error}</span></#if>
    </div>
</div>

<div class="layui-footer">
    : 欢迎使用
</div>
</div>

<script>
    var depnameback;
    function editDep(depid) {
        var editBtn = $('#edit'+depid);
        var cancelBtn = $('#cancel'+depid);
        var ele = $('#awardname'+depid);
        depnameback=ele.html();
        console.log(depnameback)
        if(cancelBtn.css('display') == 'none'){
            cancelBtn.css('display','inline');
            editBtn.html('确定');
            var depname = ele.text();
            ele.html('<input type="text" value="'+depname+'"/>')
        }else{
            var children = ele.children('input');
            var valu = children.val();
            $.post("/managerboss/editaward",{id:depid,name:valu},function (msg) {
                console.log("请求消息"+msg);
                if(msg == 'success'){
                    cancelBtn.css('display','none');
                    editBtn.html('编辑');
                    ele.html(valu);
                }
            })
        }
    }
    function cancelDep(depid) {
        var editBtn = $('#edit'+depid);
        var cancelBtn = $('#cancel'+depid);
        var ele = $('#awardname'+depid);
        cancelBtn.css('display','none');
        editBtn.html('编辑');
        ele.html(depnameback);
    }
</script>
</body>
</html>